import numpy as np
from scipy import rand
from scipy.optimize import leastsq
import pylab

n = 151
x = np.mgrid[1:10:n*1j]

def f(p, x):
  return p[0]*(1.0+p[1]*p[2]*x)**(-1.0/p[1])

def errf(p, x, y):
  return f(p, x) - y

abc = [15.0, 2.5, 0.3]
y = f(abc, x) + rand(n) - 0.5

abc_guess = [30.0, 4.0, 1.0]
abc1, success = leastsq(errf, abc_guess[:], args = (x, y))

print success	# should be 1
print abc1	# I get [ 14.71976079   2.4536336    0.27560377]

pylab.plot(x, y, x, f(abc1, x))
pylab.show()
